package com.qust.enDecrpytion.proxy.status;

import com.qust.enDecrpytion.annotations.Decryption;
import com.qust.enDecrpytion.annotations.Encryption;
import com.qust.enDecrpytion.cache.DecryptionLru;
import com.qust.enDecrpytion.cache.EncryptionLru;
import com.qust.enDecrpytion.proxy.IStatusOfType;
import lombok.Setter;

import java.lang.annotation.Annotation;

@Setter
public abstract class AbstractTypeHandle implements IStatusOfType {
    protected EncryptionLru encryptionLru;
    protected DecryptionLru decryptionLru;

    protected void add2Cache(String key, String value, Class<? extends Annotation> flag) {
        if (flag == Encryption.class) {
            encryptionLru.put(key, value);
        } else if (flag == Decryption.class) {
            decryptionLru.put(key, value);
        } else {
            throw new RuntimeException("不支持此类型注解");
        }
    }

    protected String getFromCache(String key, Class<? extends Annotation> flag) {
        if (flag == Encryption.class) {
            return encryptionLru.get(key);
        } else if (flag == Decryption.class) {
            return decryptionLru.get(key);
        } else {
            throw new RuntimeException("不支持此类型注解");
        }
    }


}
